﻿@using ZhouYu.NewWorld.Model
@{
    Layout = null;
    var brands = ViewBag.brands as List<Brand>;
    var suppliers = ViewBag.suppliers as List<Supplier>;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style>
        .right {
            display: none
        }
    </style>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="~/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/css/style.css" />
    <link href="~/assets/css/codemirror.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/assets/css/ace.min.css" />
    <link rel="stylesheet" href="~/font/css/font-awesome.min.css" />
    <link href="~/static/common/layui/css/layui.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/static/admin/css/style.css" />

    <!--[if lte IE 8]>
      <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="~/static/common/jquery-3.3.1.min.js"></script>
    <script src="~/assets/js/bootstrap.min.js"></script>
    <script src="~/assets/js/typeahead-bs2.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="~/static/common/layui/layui.js"></script>
    <script src="~/assets/layer/layer.js" type="text/javascript"></script>
    <script src="~/assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="~/Scripts/Format.js"></script>
    <script src="~/static/common/layui/lay/modules/laytpl.js"></script>
    <title>地区商品管理</title>
</head>

<body>
    <div class="margin clearfix">
        <div class="" id="Other_Management">
            <div class="border clearfix">
                <span class="l_f">
                    <a href="#" class="btn btn-danger" id="add">&nbsp;添加</a>
                </span>
            </div>
            <div class="list_style">
                <table class="layui-hide" id="test" lay-filter="demo"></table>
                <script type="text/html" id="barDemo">
                    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                </script>
            </div>
        </div>
    </div>
    <div class="right" id="app">
        <fieldset class="layui-elem-field layui-field-title">
            <legend></legend>
        </fieldset>
        <div>
            <div class="layui-form-item">
                <input type="hidden" name="GoodsId" id="GoodsId" class="layui-input" />
                <input type="hidden" name="GoodsDetails_Id" id="GoodsDetails_Id" class="layui-input" />
                <label class="layui-form-label">商品编码</label>
                <div class="layui-input-block">
                    <input type="text" name="GoodsNo" id="GoodsNo" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品名称</label>
                <div class="layui-input-block">
                    <input type="text" name="GoodsName" id="GoodsName" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品描述</label>
                <div class="layui-input-block">
                    <input type="text" name="Describe" id="Describe" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品价格</label>
                <div class="layui-input-block">
                    <input type="text" name="Price" id="Price" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">优惠价</label>
                <div class="layui-input-block">
                    <input type="text" name="Discount" id="Discount" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品重量</label>
                <div class="layui-input-block">
                    <input type="text" name="Weight" id="Weight" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">生产许可证编号</label>
                <div class="layui-input-block">
                    <input type="text" name="ProductNo" id="ProductNo" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品条形码</label>
                <div class="layui-input-block">
                    <input type="text" name="ProductCode" id="ProductCode" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">生产日期</label>
                <div class="layui-input-block">
                    <input type="date" name="ProductDate" id="ProductDate" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">有效期</label>
                <div class="layui-input-block">
                    <input type="date" name="ValidityTime" id="ValidityTime" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">厂家名</label>
            <div class="layui-input-block">
                <select name="SupplierId" id="SupplierId" style="margin-left:10px">
                    @foreach (var supplier in suppliers)
                    {
                        <option value="@supplier.SupplierId">@supplier.SupplierName</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌名称</label>
            <div class="layui-input-block">
                <select name="BrandId" id="BrandId" style="margin-left:10px">
                    @foreach (var brand in brands)
                    {
                        <option value="@brand.BrandId">@brand.BrandName</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">产品等级</label>
            <div class="layui-input-block">
                <select name="GoodsLevel" id="GoodsLevel" style="margin-left:10px">
                    <option value="1" selected=selected>一级</option>
                    <option value="2" selected=selected>二级</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="button" id="commit" value="立即提交" class="layui-btn" />
            </div>
        </div>
    </div>
</body>
</html>
<script>
    //显示
    $(function () {
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#test'
                , url: '/Goods/GetGoodsInfo'
                , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                , cols: [[
                    { type: 'checkbox' } //开启复选框
                    , { field: 'GoodsId', title: '商品Id', sort: true, width: 100 }
                    , { field: 'GoodsDetails_Id', title: '商品详情Id', sort: true, width: 100 }
                    , { field: 'GoodsNo', title: '商品编码', sort: true, width: 100 }
                    , { field: 'GoodsName', title: '商品名称', sort: true }
                    , { field: 'Describe', title: '商品描述', unresize: true }
                    , { field: 'Price', title: '商品价格', sort: true, width: 100 }
                    , { field: 'Discount', title: '优惠价', sort: true, width: 100 }
                    , { field: 'Weight', title: '商品重量', sort: true, width: 100 }
                    , { field: 'ProductNo', title: '生产许可证编号', sort: true }
                    , { field: 'ProductCode', title: '商品条形码', sort: true }
                    , { field: 'GoodsLevel', title: '产品等级', sort: true, width: 100 }
                    , { field: 'ProductDate', title: '生产日期', sort: true, templet: "<div>{{Format(d.ProductDate ,'yyyy-MM-dd hh:mm:ss')}}</div>" }
                    , { field: 'ValidityTime', title: '有效期', sort: true, templet: "<div>{{Format(d.ValidityTime ,'yyyy-MM-dd hh:mm:ss')}}</div>" }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 120 }
                ]]
                , page: true
                , id: 'testReload'
            });

            //监听行工具事件
            table.on('tool(demo)', function (obj) {
                var data = obj.data;
                if (obj.event == 'edit') {
                    layer.open({
                        type: 1,
                        title: '修改信息',
                        area: ['1050px', '800px'],
                        shadeClose: false,
                        content: $("#app"),
                    });

                    $("#GoodsId").val(data.GoodsId);
                    $("#GoodsDetails_Id").val(data.GoodsDetails_Id);
                    $("#GoodsNo").val(data.GoodsNo);
                    $("#GoodsName").val(data.GoodsName);
                    $("#Describe").val(data.Describe);
                    $("#Price").val(data.Price);
                    $("#Discount").val(data.Discount);
                    $("#Weight").val(data.Weight);
                    $("#ProductNo").val(data.ProductNo);
                    $("#ProductCode").val(data.ProductCode);
                    $("#ProductDate").val(Format(data.ProductDate ,'yyyy-MM-dd'));
                    $("#ValidityTime").val(Format(data.ValidityTime ,'yyyy-MM-dd'));
                    $("#SupplierId").val(data.SupplierId);
                    $("#BrandId").val(data.BrandId);
                    $("#GoodsLevel").val(data.GoodsLevel);


                    $("#commit").click(function () {
                        var goods = {};
                        goods.GoodsId = $("#GoodsId").val();
                        goods.GoodsDetails_Id = $("#GoodsDetails_Id").val();
                        goods.GoodsNo = $("#GoodsNo").val();
                        goods.GoodsName = $("#GoodsName").val();
                        goods.Describe = $("#Describe").val();
                        goods.Price = $("#Price").val();
                        goods.Discount = $("#Discount").val();
                        goods.Weight = $("#Weight").val();
                        goods.ProductNo = $("#ProductNo").val();
                        goods.ProductCode = $("#ProductCode").val();
                        goods.ProductDate = $("#ProductDate").val();
                        goods.ValidityTime = $("#ValidityTime").val();
                        goods.SupplierId = $("#SupplierId").val();
                        goods.BrandId = $("#BrandId").val();
                        goods.GoodsLevel = $("#GoodsLevel").val();

                        $.ajax({
                            type: "post",
                            data: goods,
                            url: "/Goods/UpdateGoods",
                            success: function (result) {
                                if (result.Success) {
                                    layer.msg('修改成功！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    }
                                        , function () { window.location.reload() });
                                } else {
                                    layer.msg('修改失败！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    });
                                }
                            }
                        });
                    });
                } else if (obj.event == 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url: "/Goods/DeleteGoods?id=" + data.GoodsId,
                            type: "post",
                            success: function (data) {
                                if (data.Success) {
                                    layer.msg('删除成功！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    }, function () {
                                        TableReload();
                                        layer.close(index);
                                    });
                                    window.location.reload();
                                }
                                else {
                                    layer.msg('删除失败！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    });
                                }
                            }
                        });
                    });
                }
            });
        });
        //添加
        $("#add").click(function () {
            layer.open({
                type: 1,
                title: "添加",
                area: ['1050px', '800px'],
                shadeClose: false,
                content: $("#app"),
            });
            $("#GoodsNo").val(null);
            $("#GoodsName").val(null);
            $("#Describe").val(null);
            $("#Price").val(null);
            $("#Discount").val(null);
            $("#Weight").val(null);
            $("#ProductNo").val(null);
            $("#ProductCode").val(null);
            $("#ProductDate").val(null);
            $("#ValidityTime").val(null);

            $("#commit").click(function () {
                if ($("#GoodsNo").val() != null && $("#GoodsNo").val() != "" && $("#GoodsName").val() != null && $("#GoodsName").val() != "" && $("#Describe").val() != null && $("#Describe").val() != "" && $("#Price").val() != null && $("#Price").val() != "" && $("#Discount").val() != null && $("#Discount").val() != "" && $("#Weight").val() != null && $("#Weight").val() != "" && $("#ProductNo").val() != null && $("#ProductNo").val() != "" && $("#ProductCode").val() != null && $("#ProductCode").val() != "" && $("#ProductDate").val() != null && $("#ProductDate").val() != "" && $("#ValidityTime").val() != null && $("#ValidityTime").val() != "") {
                    var goods = {};
                    goods.GoodsNo = $("#GoodsNo").val();
                    goods.GoodsName = $("#GoodsName").val();
                    goods.Describe = $("#Describe").val();
                    goods.Price = $("#Price").val();
                    goods.Discount = $("#Discount").val();
                    goods.Weight = $("#Weight").val();
                    goods.ProductNo = $("#ProductNo").val();
                    goods.ProductCode = $("#ProductCode").val();
                    goods.ProductDate = $("#ProductDate").val();
                    goods.ValidityTime = $("#ValidityTime").val();
                    goods.SupplierId = $("#SupplierId").val();
                    goods.BrandId = $("#BrandId").val();
                    goods.GoodsLevel = $("#GoodsLevel").val();

                    $.ajax({
                        type: "post",
                        data: goods,
                        url: "/Goods/AddGoods",
                        success: function (result) {
                            if (result.Success) {
                                layer.msg('添加成功！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                }
                                    , function () { window.location.reload() });
                            } else {
                                layer.msg('添加失败！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                });
                            }
                        },
                    });
                }
                else {
                    layer.msg('不能为空！', {
                        title: '提示框',
                        icon: 1,
                        time: 2000
                    });
                }
            });
        });
    });
</script>


<script>
    jQuery(function ($) {
        var oTable1 = $('#sample-table').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                { "orderable": false, "aTargets": [0, 2, 3, 6] }// 制定列不参与排序
            ]
        });


        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });
    });



    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $(obj).parents("tr").remove();
            layer.msg('已删除!', { icon: 1, time: 1000 });
        });
    }
    //积分浏览
    function integration_history(id) {
        layer.open({
            type: 1,
            title: '积分获取记录',
            area: ['800px', '400px'],
            shadeClose: true,
            content: $('#integration_history'),
        })
        $('#integration_history_list').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [{
                "bSortable": false,
                "orderable": false,
                "aTargets": [0, 1]
            }]
        });

    };
    //浏览记录

    function Browse_history(id) {
        layer.open({
            type: 1,
            title: '浏览记录',
            area: ['800px', '400px'],
            shadeClose: true,
            content: $('#Browse_history'),
        })
        $('#Browse_history_list').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [{
                "bSortable": false,
                "orderable": false,
                "aTargets": [0, 1]
            }]
        });
    }


    //购物记录
    function Order_history(id) {
        layer.open({
            type: 1,
            title: '购物记录',
            area: ['800px', '400px'],
            shadeClose: true,
            content: $('#Order_history'),
        });
        $('#Order_history_list').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [{
                "bSortable": false,
                "orderable": false,
                "aTargets": [0, 1]
            }]
        });
    }
</script>
